package com.uchengwang.ui.base_ui.basefm;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.umeng.analytics.MobclickAgent;

/**
 * Created by U城网 on 2017/5/10.
 */

public class BaseFragment extends Fragment{
    private View view;
    private int layoutId;
    public boolean isLoadView = false;//是否重新加载了view 判断是否重新请求网络

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        if (null != view) {
            ViewGroup parent = (ViewGroup) view.getParent();
            isLoadView =false;
            if (null != parent) {
                parent.removeView(view);
            }
        } else {
            view = inflater.inflate(layoutId,container, false);
            isLoadView = true;
        }

        return view;
    }

    @Override
    public void onResume() {
        super.onResume();
        MobclickAgent.onPageStart(getClass().getSimpleName()); //统计页面
    }

    @Override
    public void onPause() {
        super.onPause();
        MobclickAgent.onPageEnd(getClass().getSimpleName());


    }

    /**
     * 先设置Fragment界面布局
     * */
    public void setLayoutId(int layoutId){
        this.layoutId = layoutId;

    }

    @Override
    public void onDestroy() {
        super.onDestroy();
//        RefWatcher refWatcher = UChengApplication.getRefWatcher(this.getContext());//1
//        refWatcher.watch(this);
    }
}
